﻿<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>计算属性的getter和setter</title>
	</head>
	<body>
		<div id="app">
		  <p>First name: <input type="text" v-model="firstName"></p>
		  <p>Last name: <input type="text" v-model="lastName"></p>
		  <p>{{ fullName }}</p>
		</div>
	
		<script src="https://unpkg.com/vue@next"></script>
        <script>
        	const vm = Vue.createApp({
                data() {
                    return {
                        firstName: 'Smith',
                        lastName: "Will"    
                    }
                },
                computed: {
                  	fullName: {
                	    // getter
                	    get() {
                	        return this.firstName + ' ' + this.lastName
                	    },
                	    // setter
                	    set(newValue) {
                	        let names = newValue.split(' ')
                	        this.firstName = names[0]
                	        this.lastName = names[names.length - 1]
                	    }
                	}
                }
            }).mount('#app');
        </script>
	</body>
</html>